package com.zhhs.galaxyott.httpVolley.parser;

import org.json.JSONException;
import org.json.JSONObject;

import android.text.TextUtils;

import com.zhhs.galaxyott.httpVolley.response.UniversalResponse;
import com.zhhs.galaxyott.utils.Logs;

public class UniversalParser extends BaseParser<UniversalResponse> {

    @Override
    public UniversalResponse parse(String jsonString) {
        UniversalResponse response = new UniversalResponse();

        try {
            // 如果用fastJoson就是此处不同
            // JSONObject obj = JSON.parseObject(paramString);
            JSONObject obj = new JSONObject(jsonString);
            parseMsg(obj, response);

            // 先判断返回码.
            int errCode = obj.getInt("errCode");
            response.errCode = errCode;
            String returnCode = String.valueOf(errCode);

            response.setResult(obj.getInt("result"));
            String msg = obj.optString("msg");
            Logs.logD("MSG", "this is Msg-->" + msg);
            if (TextUtils.isEmpty(returnCode)) {
                return null;
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return response;
    }

}
